import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Homes from '../views/Homes.vue'
import Login from '../views/Login.vue'

const routes = [
  {
    path: '/',
    name: 'qidongye',
    component: () => import('../views/Qidongye.vue')
  },
  {
    path: '/homes',
    name: 'Homes',
    component: Homes,
    children: [
      {
        path: '/home',
        name: 'Home',
        component: Home,
      },
      {
        path: '/news',
        name: 'News',
        component: () => import(/* webpackChunkName: "News" */ '../views/News.vue')
      },
      {
        path: '/mine',
        name: 'Mine',
        component: () => import('../views/Mine.vue')
      },
    ]
  },
  {
    path: '/news/detail',
    name: 'NewsDetail',
    component: () => import('../views/NewsDetail.vue')
  },
  {
    path: '/news/kfmessage',
    name: 'KfMessage',
    component: () => import('../views/KfMessage.vue')
  },
  {
    path: '/projectlist',
    name: 'Projectlist',
    component: () => import('../views/Projectlist.vue')
  },
  {
    path: '/details',
    name: 'Details',
    component: () => import('../views/Details.vue')
  },
  // {
  //   path: '/kefu',
  //   name: 'Kefu',
  //   component: () => import('../views/Kefu.vue')
  // },
  {
    path: '/yijian',
    name: 'Yijian',
    component: () => import('../views/Yijian.vue')
  },
  {
    path: '/gywm',
    name: 'Gywm',
    component: () => import('../views/Gywm.vue')
  },
  {
    path: '/news/activemessage',
    name: 'Activemessage',
    component: () => import('../views/Activemessage.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/mine/setting',
    name: 'MineSetting',
    component: () => import('../views/MineSetting.vue')
  },
  {
    path: '/mine/setting/userrule',
    name: 'MineUserRule',
    component: () => import('../views/MineUserRule.vue')
  },
  {
    path: '/mine/setting/privacy',
    name: 'MinePrivacy',
    component: () => import('../views/MinePrivacy.vue')
  },
  {
    path: '/mine/cscenter',
    name: 'Cscenter',
    component: () => import('../views/Cscenter.vue')
  },
  {
    path: '/Iframe',
    name: 'Iframe',
    component: () => import('../views/Iframe.vue')
  },
]
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path == '/login') {
    let info = localStorage.getItem("usedata");
    if (info) {
      next(false)
    }
  }
  if (to.path == '/news') {
    let info = localStorage.getItem("usedata");
    if (!info) {
      next("/login");
    } else {
      next()
    }
  } else {
    next()
  }
});



export default router
